package com.haixiaoke.saas.manage.apartment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.apartment.domain.Require;
import com.haixiaoke.saas.apartment.service.IRequireService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 房间要求种类Controller
 * 
 * @author panda
 * @date 2024-03-21
 */
@RestController
@RequestMapping("/manage/house/require")
public class ManageRequireController extends BaseController {
    @Autowired
    private IRequireService requireService;

    /**
     * 查询房间要求种类列表
     */
    @PreAuthorize("@ss.hasPermi('business:require:list')")
    @GetMapping("/list")
    public TableDataInfo list(Require require) {
        startPage();
        List<Require> list = requireService.selectRequireList(require);
        return getDataTable(list);
    }

    /**
     * 导出房间要求种类列表
     */
    @PreAuthorize("@ss.hasPermi('business:require:export')")
    @Log(title = "房间要求种类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Require require) {
        List<Require> list = requireService.selectRequireList(require);
        ExcelUtil<Require> util = new ExcelUtil<Require>(Require.class);
        util.exportExcel(response, list, "房间要求种类数据");
    }

    /**
     * 获取房间要求种类详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:require:query')")
    @GetMapping(value = "/{requireId}")
    public AjaxResult getInfo(@PathVariable("requireId") Long requireId) {
        return success(requireService.selectRequireByRequireId(requireId));
    }

    /**
     * 新增房间要求种类
     */
    @PreAuthorize("@ss.hasPermi('business:require:add')")
    @Log(title = "房间要求种类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Require require) {
        return toAjax(requireService.insertRequire(require));
    }

    /**
     * 修改房间要求种类
     */
    @PreAuthorize("@ss.hasPermi('business:require:edit')")
    @Log(title = "房间要求种类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Require require) {
        return toAjax(requireService.updateRequire(require));
    }

    /**
     * 删除房间要求种类
     */
    @PreAuthorize("@ss.hasPermi('business:require:remove')")
    @Log(title = "房间要求种类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requireIds}")
    public AjaxResult remove(@PathVariable Long[] requireIds) {
        return toAjax(requireService.deleteRequireByRequireIds(requireIds));
    }
}
